<?php

namespace App\Http\Controllers\Advertisement;

use App\Models\AdvToutiao;
use App\Models\User;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;


class ToutiaoController extends Controller
{
    
    const ADVERTISE_SOURCE_TOUTIAO_GROUP = [
        self::ADVERTISE_SOURCE_TOU_TIAO,
        self::ADVERTISE_SOURCE_YI_MA,
        self::ADVERTISE_SOURCE_ZHONG_AN
    ];   

    const ADVERTISE_SOURCE_TOU_TIAO = 51001;//
    const ADVERTISE_SOURCE_YI_MA = 51002;//
    const ADVERTISE_SOURCE_ZHONG_AN = 51003;
    

    const ADVERTISE_SOURCE_CONFLICT = [
        self::ADVERTISE_SOURCE_TOU_TIAO=>'头条',
        self::ADVERTISE_SOURCE_YI_MA=>'亿玛',
        self::ADVERTISE_SOURCE_ZHONG_AN=>'众安'
    ];
    const DEVICE_TYPE_IMEI = 1;//安卓设备类型 imei
    const DEVICE_TYPE_ANDROID_ID = 2;//安卓设备类型androidid

    const OS_TYPE_ANDROID = 0;//系统类型 android
    const OS_TYPE_IOS = 1;//系统类型 ios

    const OS_TYPE_PARAM = [
        self::OS_TYPE_ANDROID ,
        self::OS_TYPE_IOS ,
    ];

    const USER_STATUS_CLICK = 0;//点击
    const USER_STATUS_ACTIVE = 1;//激活
    const USER_STATUS_REGISTER = 2;//注册
    const USER_STATUS_LOAN_REQUEST = 3;//授信

    const ADVERTISE_PALCE_TYPE_ONE = 1;//
    const ADVERTISE_PALCE_TYPE_TWO = 2;//
    const ADVERTISE_PALCE_TYPE_THREE = 3;//
    const ADVERTISE_PALCE_TYPE_FOUR = 4;//
    const ADVERTISE_PALCE_TYPE_FIVE = 5;//
    const ADVERTISE_PALCE_TYPE_SIX = 6;//
    const ADVERTISE_PALCE_TYPE_SEVEN = 7;//
    const ADVERTISE_PALCE_TYPE_EIGHT = 8;//
    const ADVERTISE_PALCE_TYPE_NINE = 9;//
    const ADVERTISE_PALCE_TYPE_TEN = 10;//

    const ADVERTISE_EFFECTIVE_CUSTOMER = 19;
    public function index(Request $request){
        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
    }


    public function advertise_toutiao_android(Request $request) {

//        dd($request->input('callback_url'));
//        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
        $adid = $request->input('adid','');//广告计划 id 原值
        $cid = $request->input('cid','');//广告创意 id
        $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
        $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
        $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
        if(is_null($idfa)) {
            $idfa = '';
        }
        $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
        if(is_null($androidid)) {
            $androidid = '';
        }
        $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
        if(is_null($imei)) {
            $imei = '';
        }
        $os = $request->input('os','');
        $callback_url = $request->input('callback','');
        $timestamp = $request->input('timestamp',time());
        if (!is_int($timestamp)) {
            $timestamp = time();
        }
        try{
            $adv_toutiao = new AdvToutiao();
            if (!empty($imei)) {
                $has_advertise = $adv_toutiao
                    ->where('imei',$imei)
                    ->value('imei');

                if (!empty($has_advertise)) {
                   
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }

            }else{
                if (!empty($androidid)) {
                    $has_advertise = $adv_toutiao
                        ->where('androidid',$androidid)
                        ->first();
                    if ($has_advertise) {
                        Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        return json_encode(['status'=>1]);
                    }

                }
            }
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];

            $adv_toutaio = AdvToutiao::create($data);

        }catch (\Exception $exception) {
            Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
        }
        return json_encode(['status'=>0]);

    }

    public function advertise_toutiao_ios(Request $request) {
        // Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
        $adid = $request->input('adid','');//广告计划 id 原值
        $cid = $request->input('cid','');//广告创意 id
        $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
        $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
        $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
        $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
        $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
        $os = $request->input('os','');
        $callback_url = $request->input('callback','');
        $timestamp = $request->input('timestamp',time());
        if (!is_int($timestamp)) {
            $timestamp = time();
        }
        $adv_toutiao = new AdvToutiao();
        if (!empty($idfa)) {
            $has_advertise = $adv_toutiao
                ->where('idfa',$idfa)
                ->first();
            if ($has_advertise) {
                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
        }

        $data = [
            'adid'=>$adid,
            'cid'=>$cid,
            'csite'=>$csite,
            'ctype'=>$ctype,
            'idfa'=>$idfa,
            'androidid'=>$androidid,
            'imei'=>$imei,
            'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
            'os'=>$os,
            'callback_url'=>$callback_url,
            'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
        ];
        try{
            $adv_toutaio = AdvToutiao::create($data);

        }catch (\Exception $exception) {
            Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return json_encode(['status'=>1]);
        }
        return json_encode(['status'=>0]);

    }


    /**
     * @param Request $request
     * 激活推送
     * @authod liChunLong
     */
    public function advertise_active_push(Request $request) {
         //0.点击，1.激活，2.注册,3.申请
        $os_type = $request->input('os_type');
        $device_uuid = $request->input('device_uuid');
        $device_type = $request->input('device_type',1); //1.imei 2,androidid
        if(!in_array($os_type,self::OS_TYPE_PARAM)){
            return failed('请输入手机系统类型');
        }
        try {
            if ($os_type == self::OS_TYPE_IOS) { //ios
                $adv_toutiao = new AdvToutiao();
                $has_advertise = $adv_toutiao->where('os',1)
                    ->where('idfa',$device_uuid)
                    ->where('user_status',self::USER_STATUS_CLICK)
                    ->first();
                //0，仅仅点击操作，还没激活过
                if ($has_advertise) {
                    if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {
                    // if($has_advertise->source == self::ADVERTISE_SOURCE_TOU_TIAO) {
                        //0 点击
                        AdvToutiao::where('os',1)
                            ->where('idfa',$device_uuid)
                            ->where('user_status',self::USER_STATUS_CLICK)
                            ->update(['user_status'=>self::USER_STATUS_ACTIVE]);

                        // 推送事件 该用户激活
                        $sent_url = $has_advertise->callback_url;
                        $sent_url .= '&event_type=0';
                        $ret = $this->send_toutiao_event($sent_url);
                        if($ret['ret'] != 0){
                            Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }else {
                            Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }
                    }
                }
            }else { //android
                $adv_toutiao = new AdvToutiao();
                if ($device_type == self::DEVICE_TYPE_IMEI) {
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('imei',md5($device_uuid))
                        ->where('user_status',self::USER_STATUS_CLICK)
                        ->first();
                
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                        
                            $ret = AdvToutiao::where('os',0)
                                ->where('imei',md5($device_uuid))
                                ->where('user_status',self::USER_STATUS_CLICK)
                                ->update(['user_status'=>self::USER_STATUS_ACTIVE]);
                                
                            // 推送事件 该用户激活
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=0';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }else{
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('androidid',$device_uuid)
                        ->where('user_status',self::USER_STATUS_CLICK)
                        ->first();
                        
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                        
                            //0 点击
                            AdvToutiao::where('os',0)
                                ->where('androidid',$device_uuid)
                                ->where('user_status',self::USER_STATUS_CLICK)
                                ->update(['user_status'=>self::USER_STATUS_ACTIVE]);
                            //推送事件 该用户激活
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=0';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }
            }
        }catch (\Exception $exception) {
            Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return failed($exception->getMessage());
        }
        return success([]);

    }
    /**
     * @param Request $request
     * 注册推送
     * @authod liChunLong
     */
    public function advertise_register_push(Request $request) {
        $os_type = $request->input('os_type');//0.android 1.ios
        $device_uuid = $request->input('device_uuid');
        $device_type = $request->input('device_type'); //1.imei 2,android
        $phone_num = $request->input('phone_num','');
        if (is_null($phone_num)) {
            $phone_num = '';
        }
        $user_id = '';
        if(!empty($phone_num)) {
            $user_id = User::where('phone_num','=',$phone_num)->value('id');  
            if( $user_id < 1) {
                $user_id = '';
                \Log::debug('头条注册手机号码未查到对应用户！接受参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            } 
        } else {
            \Log::debug('头条注册未传手机号码！接受参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
        }
        if(!in_array($os_type,self::OS_TYPE_PARAM)){
            return failed('请输入手机系统类型');
        }
        try {
            if ($os_type == self::OS_TYPE_IOS) { //ios
                $adv_toutiao = new AdvToutiao();
                $has_advertise = $adv_toutiao->where('os',1)
                    ->where('idfa',$device_uuid)
                    ->where('user_status',self::USER_STATUS_ACTIVE)
                    ->first();
                //0，仅仅激活操作，还没注册过
                if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                
                        //0 点击
                        AdvToutiao::where('os',1)
                            ->where('idfa',$device_uuid)
//                            ->where('user_status',self::USER_STATUS_ACTIVE)
                            ->update(['user_status'=>self::USER_STATUS_REGISTER, 'user_id'=>$user_id]);
                        //todo 推送事件 该用户注册
                        $sent_url = $has_advertise->callback_url;
                        $sent_url .= '&event_type=1';
                        $ret = $this->send_toutiao_event($sent_url);
                        if($ret['ret'] != 0){
                            Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }else {
                            Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }
                    }
                }
            }else { //android
                $adv_toutiao = new AdvToutiao();
                if ($device_type == self::DEVICE_TYPE_IMEI) {
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('imei',md5($device_uuid))
                        ->where('user_status',self::USER_STATUS_ACTIVE)
                        ->first();
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                            AdvToutiao::where('os',0)
                                ->where('imei',md5($device_uuid))
                                ->where('user_status',self::USER_STATUS_ACTIVE)
                                ->update(['user_status'=>self::USER_STATUS_REGISTER, 'user_id'=>$user_id]);
                            // 推送事件 该用户注册
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=1';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }else{
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('androidid',$device_uuid)
                        ->where('user_status',self::USER_STATUS_ACTIVE)
                        ->first();
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                            //0 点击
                            AdvToutiao::where('os',0)
                                ->where('androidid',$device_uuid)
//                                ->where('user_status',self::USER_STATUS_ACTIVE)
                                ->update(['user_status'=>self::USER_STATUS_REGISTER, 'user_id'=>$user_id]);
                            // 推送事件 该用户注册
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=1';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }

            }
        }catch (\Exception $exception) {
            Log::debug('头条用户注册同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return failed($exception->getMessage());
        }
        return success([]);

    }

    /**
     * @param Request $request
     * 授信推送
     * @authod liChunLong
     */
    public function advertise_loan_request_push(Request $request) {
        $os_type = $request->input('os_type','');//0.android 1.ios
        $device_uuid = $request->input('device_uuid','');
        $device_type = $request->input('device_type',''); //1.imei 2,android
        $phone_num = $request->input('phone_num','');//手机号
        if(!in_array($os_type,self::OS_TYPE_PARAM)){
            return failed('请输入手机系统类型');
        }
        $user_id = User::where('phone_num',$phone_num)->value('id');
        $click_id = AdvToutiao::where('user_id',$user_id)->value('click_id');
        try{
            if($click_id) {//h5
                $adv_toutiao = new AdvToutiao();
                $has_advertise = $adv_toutiao
                    ->where('click_id',$click_id)
                    ->where('user_status',self::USER_STATUS_REGISTER)
                    ->first();
                //0，仅仅激活操作，还没注册过
                if ($has_advertise) {
                    if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                        //0 点击
                        AdvToutiao::where('click_id',$click_id)
                            ->where('user_status',self::USER_STATUS_REGISTER)
                            ->update(['user_status'=>self::USER_STATUS_LOAN_REQUEST, 'user_id'=>$user_id]);
                        //todo 推送事件 该用户授信
                        $sent_url = 'http://ad.toutiao.com/track/activate/?';
                        $data =[
                            'callback'=>$has_advertise->click_id,
                            'source'=>$has_advertise->source,
                            'event_type'=>self::ADVERTISE_EFFECTIVE_CUSTOMER,
                        ];
                        $sent_url .= http_build_query($data);
                        $ret = $this->send_toutiao_event($sent_url);
                        if($ret['ret'] != 0){
                            Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }else {
                            Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }

                    }
                }
            }
            if ($os_type == self::OS_TYPE_IOS) { //ios
                $adv_toutiao = new AdvToutiao();
                $has_advertise = $adv_toutiao->where('os',1)
                    ->where('idfa',$device_uuid)
                    ->where('user_status',self::USER_STATUS_REGISTER)
                    ->first();
                //0，仅仅激活操作，还没注册过
                if ($has_advertise) {
                    if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                        //0 点击
                        AdvToutiao::where('os',1)
                            ->where('idfa',$device_uuid)
                            ->where('user_status',self::USER_STATUS_REGISTER)
                            ->update(['user_status'=>self::USER_STATUS_LOAN_REQUEST, 'user_id'=>$user_id]);
                        //todo 推送事件 该用户授信
                        $sent_url = $has_advertise->callback_url;
                        $sent_url .= '&event_type=2';
                        $ret = $this->send_toutiao_event($sent_url);
                        if($ret['ret'] != 0){
                            Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }else {
                            Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        }

                    }
                }
            }else { //android
                $adv_toutiao = new AdvToutiao();
                if ($device_type == self::DEVICE_TYPE_IMEI) {
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('imei',md5($device_uuid))
                        ->where('user_status',self::USER_STATUS_REGISTER)
                        ->first();
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                            AdvToutiao::where('os',0)
                                ->where('imei',md5($device_uuid))
                                ->where('user_status',self::USER_STATUS_REGISTER)
                                ->update(['user_status'=>self::USER_STATUS_LOAN_REQUEST, 'user_id'=>$user_id]);
                            //todo 推送事件 该用户授信
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=2';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }else{
                    $has_advertise = $adv_toutiao->where('os',0)
                        ->where('androidid',$device_uuid)
                        ->where('user_status',self::USER_STATUS_REGISTER)
                        ->first();
                    //0，仅仅点击操作，还没激活过
                    if ($has_advertise) {
                        if (in_array($has_advertise->source,self::ADVERTISE_SOURCE_TOUTIAO_GROUP)) {                    
                            //0 点击
                            AdvToutiao::where('os',0)
                                ->where('androidid',$device_uuid)
                                ->where('user_status',self::USER_STATUS_REGISTER)
                                ->update(['user_status'=>self::USER_STATUS_LOAN_REQUEST, 'user_id'=>$user_id]);
                            // 推送事件 该用户授信
                            $sent_url = $has_advertise->callback_url;
                            $sent_url .= '&event_type=2';
                            $ret = $this->send_toutiao_event($sent_url);
                            if($ret['ret'] != 0){
                                Log::debug('头条用户激活同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }else {
                                Log::debug('头条用户激活同步成功，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            }
                        }
                    }
                }
            }
        }catch (\Exception $exception){
            Log::debug('头条用户授信同步失败，参数：'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return failed($exception->getMessage());
        }
        return success([]);
    }

    private function send_toutiao_event($url='',$method='GET') {
        // return json_decode(['ret'=>0]);
//        $http_url = "http://kadai.in/api/adv/testGuzzleHttp";
        $http_url = $url;
        $client = new Client();
        $response = $client->request($method, $http_url);
        return  json_decode($response->getBody()->getContents(), true);
    }

    public function testGuzzleHttp() {
        return \GuzzleHttp\json_encode(['status'=>0]);
    }

//头条分区 1
    public function advertise_toutiao_android_01(Request $request) {

    //        dd($request->input('callback_url'));
    //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
            $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            if(is_null($idfa)) {
                $idfa = '';
            }
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            if(is_null($androidid)) {
                $androidid = '';
            }
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            if(is_null($imei)) {
                $imei = '';
            }
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            try{
                $adv_toutiao = new AdvToutiao();
                if (!empty($imei)) {
                    $has_advertise = $adv_toutiao
                        ->where('imei',$imei)
                        ->value('imei');
    
                    if (!empty($has_advertise)) {
                       
                        Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                        return json_encode(['status'=>1]);
                    }
    
                }else{
                    if (!empty($androidid)) {
                        $has_advertise = $adv_toutiao
                            ->where('androidid',$androidid)
                            ->first();
                        if ($has_advertise) {
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
    
                    }
                }
                $data = [
                    'adid'=>$adid,
                    'cid'=>$cid,
                    'csite'=>$csite,
                    'ctype'=>$ctype,
                    'idfa'=>$idfa,
                    'androidid'=>$androidid,
                    'imei'=>$imei,
                    'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                    'os'=>$os,
                    'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_ONE,
                    'callback_url'=>$callback_url,
                    'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                ];
    
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
            }
            return json_encode(['status'=>0]);
    
        }
    
    public function advertise_toutiao_ios_01(Request $request) {
        Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
        $adid = $request->input('adid','');//广告计划 id 原值
        $cid = $request->input('cid','');//广告创意 id
        $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
        $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
        $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
        $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
        $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
        $os = $request->input('os','');
        $callback_url = $request->input('callback','');
        $timestamp = $request->input('timestamp',time());
        if (!is_int($timestamp)) {
            $timestamp = time();
        }
        $adv_toutiao = new AdvToutiao();
        if (!empty($idfa)) {
            $has_advertise = $adv_toutiao
                ->where('idfa',$idfa)
                ->first();
            if ($has_advertise) {
                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
        }

        $data = [
            'adid'=>$adid,
            'cid'=>$cid,
            'csite'=>$csite,
            'ctype'=>$ctype,
            'idfa'=>$idfa,
            'androidid'=>$androidid,
            'imei'=>$imei,
            'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
            'os'=>$os,
            'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_ONE,
            'callback_url'=>$callback_url,
            'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
        ];
        try{
            $adv_toutaio = AdvToutiao::create($data);

        }catch (\Exception $exception) {
            Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            return json_encode(['status'=>1]);
        }
        return json_encode(['status'=>0]);

    }
    //头条分区2
    public function advertise_toutiao_android_02(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_TWO,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_02(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_TWO,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 3
    public function advertise_toutiao_android_03(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_THREE,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_03(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_THREE,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 4
    public function advertise_toutiao_android_04(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_FOUR,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_04(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_FOUR,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 5
    public function advertise_toutiao_android_05(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_FIVE,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_05(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_FIVE,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 6
    public function advertise_toutiao_android_06(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_SIX,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_06(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_SIX,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 7
    public function advertise_toutiao_android_07(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_SEVEN,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_07(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_SEVEN,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 8
    public function advertise_toutiao_android_08(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_EIGHT,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_08(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_EIGHT,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 9
    public function advertise_toutiao_android_09(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_NINE,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_09(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_NINE,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
    //头条分区 10
    public function advertise_toutiao_android_10(Request $request) {

        //        dd($request->input('callback_url'));
        //        Log::debug('请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                $adid = $request->input('adid','');//广告计划 id 原值
                $cid = $request->input('cid','');//广告创意 id
                $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
                $ctype = $request->input('ctype','');//创意样式 2=小图模式 3=大图式 4=组图模式 5=视频
                $idfa = $request->get('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
                if(is_null($idfa)) {
                    $idfa = '';
                }
                $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
                if(is_null($androidid)) {
                    $androidid = '';
                }
                $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
                if(is_null($imei)) {
                    $imei = '';
                }
                $os = $request->input('os','');
                $callback_url = $request->input('callback','');
                $timestamp = $request->input('timestamp',time());
                if (!is_int($timestamp)) {
                    $timestamp = time();
                }
                try{
                    $adv_toutiao = new AdvToutiao();
                    if (!empty($imei)) {
                        $has_advertise = $adv_toutiao
                            ->where('imei',$imei)
                            ->value('imei');
        
                        if (!empty($has_advertise)) {
                           
                            Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                            return json_encode(['status'=>1]);
                        }
        
                    }else{
                        if (!empty($androidid)) {
                            $has_advertise = $adv_toutiao
                                ->where('androidid',$androidid)
                                ->first();
                            if ($has_advertise) {
                                Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                                return json_encode(['status'=>1]);
                            }
        
                        }
                    }
                    $data = [
                        'adid'=>$adid,
                        'cid'=>$cid,
                        'csite'=>$csite,
                        'ctype'=>$ctype,
                        'idfa'=>$idfa,
                        'androidid'=>$androidid,
                        'imei'=>$imei,
                        'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                        'os'=>$os,
                        'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_TEN,
                        'callback_url'=>$callback_url,
                        'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
                    ];
        
                    $adv_toutaio = AdvToutiao::create($data);
        
                }catch (\Exception $exception) {
                    Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1,'msg'=>$exception->getMessage()]);
                }
                return json_encode(['status'=>0]);
        
            }
        
        public function advertise_toutiao_ios_10(Request $request) {
            Log::debug('头条请求参数'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
            $adid = $request->input('adid','');//广告计划 id 原值
            $cid = $request->input('cid','');//广告创意 id
            $csite = $request->input('csite','');//广告投放位置 1=头条信息流、3=详情页、11=段子 信息流
            $ctype = $request->input('ctype','');//⽤户终端的 eth0 接⼝的 MAC 地址 去除分隔符 ":",(采用获取原始值)取md5sum 摘要（备注：入网硬件地址）
            $idfa = $request->input('idfa','');//iOS IDFA 适用 iOS6及以上,原值（备注：iOS 手机广告唯一标识）
            $androidid = $request->input('androidid','');//用户终端的AndroidID，原值（备注：安卓硬件设备唯一标识）
            $imei = $request->input('imei','');//用户终端的IMEI,15 位数字
            $os = $request->input('os','');
            $callback_url = $request->input('callback','');
            $timestamp = $request->input('timestamp',time());
            if (!is_int($timestamp)) {
                $timestamp = time();
            }
            $adv_toutiao = new AdvToutiao();
            if (!empty($idfa)) {
                $has_advertise = $adv_toutiao
                    ->where('idfa',$idfa)
                    ->first();
                if ($has_advertise) {
                    Log::debug("头条用户转化失败：原因：重复添加，请求参数：".json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                    return json_encode(['status'=>1]);
                }
            }
    
            $data = [
                'adid'=>$adid,
                'cid'=>$cid,
                'csite'=>$csite,
                'ctype'=>$ctype,
                'idfa'=>$idfa,
                'androidid'=>$androidid,
                'imei'=>$imei,
                'source'=>self::ADVERTISE_SOURCE_TOU_TIAO,
                'os'=>$os,
                'adv_place_type'=>self::ADVERTISE_PALCE_TYPE_TEN,
                'callback_url'=>$callback_url,
                'user_click_time'=>date('Y-m-d H:i:s',substr($timestamp,0,10)),
            ];
            try{
                $adv_toutaio = AdvToutiao::create($data);
    
            }catch (\Exception $exception) {
                Log::debug("头条用户转化异常：原因：".$exception->getMessage().'请求参数:'.json_encode($request->all(),JSON_UNESCAPED_UNICODE));
                return json_encode(['status'=>1]);
            }
            return json_encode(['status'=>0]);
    
        }
}
